package com.welike.shibo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.welike.shibo.eneity.Push;
import com.welike.shibo.mapper.PushMapper;
import com.welike.shibo.service.PushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by fangyu on 2019-09-09.
 */
@Service
public class PushServiceImpl extends ServiceImpl<PushMapper, Push> implements PushService {

    @Autowired
    private PushMapper pushMapper;

    @Override
    public Push queryByUid(String uid) {
        return pushMapper.queryByUid(uid);
    }

    @Override
    public boolean updateByUid(Push push, String uid) {
        return pushMapper.updateByUid(push, uid);
    }

    @Override
    public boolean querySwitch(Integer type, String uid) {
        // 先查, 没有记录则插入
        Push push = this.queryByUid(uid);
        // 如果为空则没有记录直接插入
        if (push == null) {
            push = new Push();
            push.setUid(uid);
            push.setZan(true);
            push.setFollow(true);
            push.setComment(true);
            this.save(push);
        }
        if (type == 1) {
            return pushMapper.queryZanByUid(uid);
        } else if (type == 2) {
            return pushMapper.queryFollowByUid(uid);
        } else if (type == 3 || type == 4) {
            return pushMapper.queryCommentByUid(uid);
        } else {
            return false;
        }
    }
}
